package com.kai.service.ipml;

import com.kai.Util.MyExportExcelUtils;
import com.kai.entity.WalletHot;
import com.kai.mapper.second.WalletHotMapper;
import com.kai.service.ExportService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;


@Service("ExportService")
public class ExportServiceImpl  implements ExportService {


    @Resource
    private WalletHotMapper walletHotMapper;

    /**
     * 导出业务基础信息
     */
    @Override
    public void exportwalletHotBasicInfo(WalletHot w, HttpServletResponse response) {

        //获取数据集合
        List<WalletHot> dataList = walletHotMapper.selectWalletHot(w);

        //拼接标题
        //时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

        /**
         * 根据关区代号，拼接关区导出文件的名字
         */
       // String area = serviceUtilImpl.selectAreaName(params);

        //标题
        String title ="业务基础信息";

        //创建导出表格的列名
        List<String> rowName = new ArrayList<>();
        rowName.add("序号");
        rowName.add("上传时间");
        rowName.add("系统编号");
        rowName.add("报关单号");
        rowName.add("报关单状态");
        rowName.add("申报时间");
        rowName.add("收发货人");
        rowName.add("生产销售单位");
        rowName.add("申报单位");
        rowName.add("公司ID");
        rowName.add("公司名称");
        rowName.add("操作ID");
        rowName.add("操作");
        rowName.add("业务类型");
        rowName.add("申报现场");
        rowName.add("进出口岸");
        rowName.add("监管方式");
        rowName.add("成交方式");
        rowName.add("备案号");
        rowName.add("上传通道");

        if (dataList == null || dataList.size() == 0) {
            try {
                // excel 表文件名
                String fileName = title + ".csv";
                fileName = "attachment;filename=" + new String(fileName.getBytes("gbk"), "iso8859-1");
                response.setContentType("application/vnd.ms-excel;charset=utf-8");
                response.setHeader("Content-Disposition", fileName);
                OutputStream out = response.getOutputStream();
                out.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        //导出数据
        if (dataList != null && dataList.size() > 0) {
            MyExportExcelUtils myExportExcelUtils = new MyExportExcelUtils(title, rowName, dataList, response);
            myExportExcelUtils.exportCompanyDanCountData();
        }
    }


}
